package com.freeman.cement.controller;

import com.freeman.cement.annotation.NeedRole;
import com.freeman.cement.entity.AutoAssignmentConfig;
import com.freeman.cement.entity.ResponseResult;
import com.freeman.cement.service.AutoAssignmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自动转发配置Controller
 */
@RestController
@RequestMapping("/assignment")
@CrossOrigin    //允许跨域访问
public class AutoAssignmentController {

    @Resource
    private AutoAssignmentService autoAssignmentService;

    /**
     * 分页模糊查询自动转发规则列表
     *
     * @param cameraName    摄像头名称模糊
     * @param eventTypeName 事件类型名称模糊
     * @param recvUserName  接收人名称模糊
     * @param isEnabled     是否启用规则
     * @param isSmsEnabled  是否启用短信转发
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/selectAssignments", method = RequestMethod.POST)
    public ResponseResult selectAssignmentFuzzy(String cameraName, String eventTypeName, String recvUserName, Boolean isEnabled, Boolean isSmsEnabled, @RequestParam int pageNo, @RequestParam int pageSize) {
        return autoAssignmentService.selectAssignmentFuzzy(cameraName, eventTypeName, recvUserName, isEnabled, isSmsEnabled, pageNo, pageSize);
    }

    /**
     * 根据id获取自动转发规则
     *
     * @param id 自动转发规则主键id
     * @return
     */
    @RequestMapping(value = "/getAssignment", method = RequestMethod.POST)
    public ResponseResult selectAssignmentById(@RequestParam("id") int id) {
        return autoAssignmentService.selectAssignmentById(id);
    }

    /**
     * 新增自动转发规则
     *
     * @param assignment
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/addAssignment", method = RequestMethod.POST)
    public ResponseResult addAssignment(AutoAssignmentConfig assignment) {
        return autoAssignmentService.addAssignment(assignment);
    }

    /**
     * 删除自动转发规则
     *
     * @param id
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/deleteAssignment", method = RequestMethod.POST)
    public ResponseResult deleteAssignment(@RequestParam("id") int id) {
        return autoAssignmentService.deleteAssignment(id);
    }

    /**
     * 修改自动转发规则
     *
     * @param id           规则主键id
     * @param userIds     用户id集合，格式"1,2,3"
     * @param isEnabled    是否启用规则
     * @param isSmsEnabled 是否启用短信通知
     * @param remark       备注
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/updateAssignment", method = RequestMethod.POST)
    public ResponseResult updateAssignment(@RequestParam("id") int id, String userIds, Boolean isEnabled, Boolean isSmsEnabled, String remark) {
        return autoAssignmentService.updateAssignment(id, userIds, isEnabled, isSmsEnabled, remark);
    }

}
